$(function () {
    $.ajax({
        type: "get",
        url: "/UserServlet.do",
        data: {action: "getUser"},
        dataType: "Json",
        success: function (data) {
            if (data.url != location.pathname) {
                location.href = data.url;
            } else {
                if (data.user.headPic) {
                    $("img[class=layui-nav-img]").attr("src", data.user.headPic);
                }
                if (data.user.name) {
                    $("img[class=layui-nav-img]").after("欢迎，"+data.user.name+"");
                }
            }
        }
    });
    $("#loginOut").click(function () {
        var b = true;
        $.ajax({
            type: "get",
            url: "/UserServlet.do",
            data: {action: "loginOut"},
            success: function () {
                location.href = "login.html";
                b = false;
            }
        });
        return b;
    });
});